package com.eight.homepage.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.eight.common.pojo.TbHeadNav;
import com.eight.homepage.dao.TbHeadNavDao;
import com.eight.homepage.service.TbHeadService;
import com.eight.homepage.vo.TbHeadNavVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @author 向文豪
 * @program: eight-education-parent
 * @description:
 * @date 2023/5/27 16:12
 */
@Service
public class TbHeadServiceImpl implements TbHeadService {

    @Autowired
    private TbHeadNavDao tbHeadNavDao;
    @Override
    public Page<TbHeadNav> findPage(Integer currentSize, Integer pageSize, TbHeadNavVo tbHeadNavVo) {
        Page<TbHeadNav> page = new Page<>(currentSize,pageSize);
        QueryWrapper<TbHeadNav> wrapper = new QueryWrapper<>();
        if(StringUtils.hasText(tbHeadNavVo.getHeadName())){
            wrapper.like("head_name",tbHeadNavVo.getHeadName());
        }
        if(StringUtils.hasText(tbHeadNavVo.getIsDiable())){
            wrapper.eq("is_diable",tbHeadNavVo.getIsDiable());
        }
        Page<TbHeadNav> navPage = tbHeadNavDao.selectPage(page, wrapper);
        return navPage;
    }

    @Override
    public int updateStatus(Integer id, String status) {

        TbHeadNav tbHeadNav = new TbHeadNav();
        tbHeadNav.setHeadId(id);
        tbHeadNav.setIsDiable(status);
        UpdateWrapper<TbHeadNav> wrapper = new UpdateWrapper<>();
        wrapper.eq("head_id",id);
        int i = tbHeadNavDao.update(tbHeadNav,wrapper);
        return i;
    }

    @Override
    public int delete(Integer id) {
        QueryWrapper<TbHeadNav> wrapper = new QueryWrapper<>();
        if(id!= null){
            wrapper.eq("head_id",id);
        }
        int delete = tbHeadNavDao.delete(wrapper);
        return delete;
    }

    @Override
    public int insert(TbHeadNav tbHeadNav) {
       tbHeadNav.setIsDelete("0");
       tbHeadNav.setIsDiable("0");
        int insert = tbHeadNavDao.insert(tbHeadNav);
        return insert;
    }

    @Override
    public int updateHead(TbHeadNav tbHeadNav) {

        int i = tbHeadNavDao.updateById(tbHeadNav);
        return i;
    }
}
